{% extends 'core/base.html' %}
{% load staticfiles %}
{% load distro_tracker_extras %}

{% block extra-js %}
<script src="{% static 'accounts/js/profile.js' %}"></script>
<script type="text/x-dtracker-url" id="all-keywords-url">{% url 'dtracker-api-keywords' %}</script>
<script type="text/x-dtracker-url" id="update-keywords-url">{% url 'dtracker-api-accounts-profile-keywords' %}</script>
{% endblock %}

{% block content %}
{% include 'accounts/_choose-keywords-modal.html' %}

{% with team=membership.team %}
{% with email=membership.user_email.email %}
{% with accordion_id="accordion-membership-packages" %}
<h1 class="text-xs-center">Membership management for <a href="{{ team.get_absolute_url }}">{{ team }}</a></h1>
<div>
<div class="accordion list-group" id="{{ accordion_id }}">
    {% for pkg in package_list %}
    <div class="panel accordion-group list-group-item">
        <div class="accordion-heading">
            <div class="row">
            <div class="col-md-10">
	    <button class="btn btn-sm btn-default" data-toggle="collapse"
		data-parent="#{{ accordion_id }}" data-target="#{{ accordion_id }}-details-{{ forloop.counter }}">{% toggle_chevron %}</button>
            {% if pkg.get_absolute_url %}
            <a href="{{ pkg.get_absolute_url }}">{{ pkg }}</a>
            {% else %}
            <span>{{ pkg }}</span>
            {% endif %}
            </div>
            <div class="col-md-2">
        {% if pkg.is_muted %}
            <form style="margin-bottom: 0px;" action="{% url 'dtracker-team-unmute' team.slug %}" method="POST">{% csrf_token %}
                <input type="hidden" name="package" value="{{ pkg }}">
                <input type="hidden" name="email" value="{{ email }}">
                <input type="hidden" name="next" value="{% url 'dtracker-team-manage-membership' team.slug %}?page={{ page_obj.number }}&email={{ email }}">
                <button class="btn btn-primary toggle-package-mute" data-email="{{ email }}" data-package="{{ subscription.package }}">Unmute</button>
            </form>
        {% else %}
            <form style="margin-bottom: 0px;" action="{% url 'dtracker-team-mute' team.slug %}" method="POST">{% csrf_token %}
                <input type="hidden" name="package" value="{{ pkg }}">
                <input type="hidden" name="email" value="{{ email }}">
                <input type="hidden" name="next" value="{% url 'dtracker-team-manage-membership' team.slug %}?page={{ page_obj.number }}&email={{ email }}">
                <button class="btn btn-danger toggle-package-mute" data-email="{{ email }}" data-package="{{ subscription.package }}">Mute</button>
            </form>
        {% endif %}
            </div>
            </div>
        </div>
        <div class="accordion-body collapse" id="{{ accordion_id }}-details-{{ forloop.counter }}">
            <div class="accordion-inner">
            <div><b>Package specific keywords:</b></div>
            <ul class="list-inline">
                {% for keyword in pkg.keywords %}
                <li class='keyword'>{{ keyword }}</li>
                {% endfor %}
            </ul>
            <div class="btn btn-primary btn-sm modify-team-package-keywords" data-email="{{ email }}" data-package="{{ pkg }}" data-href="{% url 'dtracker-team-set-keywords' membership.team.slug %}">Modify</div>
            </div>
        </div>
    </div>
    {% endfor %}
</div>
</div>
{% endwith %}{% endwith %}{% endwith %}

{% if is_paginated %}
<div class="text-xs-center">
<ul class="pagination">
    {% for page in page_obj.paginator.page_range %}
    <li class="page-item{% if page_obj.number == page %} active{% endif %}"><a class="page-link" href="?page={{ page }}&email={{ membership.user_email.email }}">{{ page }}</a></li>
    {% endfor %}
</ul>
</div>
</div>
{% endif %}
{% endblock %}
